/**
 * @project_name staff_vehicle
 * @package_name com.ssh.web
 * @desc TODO
 * @param
 * @author jack
 * @date 2013-4-24
 * @time 上午10:40:01
 */
package com.ssh.web.caction;

import java.sql.Timestamp;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.ssh.entity.FcarAplly;
import com.ssh.entity.StaffApplyCar;
import com.ssh.entity.StaffUseCar;
import com.ssh.ser.common.ApplySerI;
import com.ssh.ser.extra.FVApplySerI;

/**
 * @author jack
 *
 */
public class ApplyCarAction extends ActionSupport {
	/**
	 * TODO
	 */
	private static final long serialVersionUID = 1L;
	private Timestamp applyDate;
	private String applyReason;
	private ApplySerI applySerI;
	private Timestamp duration;//使用时间
	private String reviewerId;
	private String idApplyCar;//申请人编号
	private String idUseCar;//使用人编号
	private String vehicleType;
	private FVApplySerI fVApplySerI;

	public FVApplySerI getfVApplySerI() {
		return fVApplySerI;
	}

	public void setfVApplySerI(FVApplySerI fVApplySerI) {
		this.fVApplySerI = fVApplySerI;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return applyCar();
	}

	public String applyCar(){
		try {
			if(!idUseCar.equals("")&&!idApplyCar.equals("")){
				StaffApplyCar staffApplyCar = new StaffApplyCar();

				Timestamp applytime = new Timestamp(System.currentTimeMillis());
				//申请信息
				staffApplyCar.setApplyDate(applytime);
				staffApplyCar.setApplyReason(applyReason);
				staffApplyCar.setDuration(duration);//申请使用时间
				staffApplyCar.setReviewerId("admin");//审核人ID号
				staffApplyCar.setRComments("等待批准");//审核意见
				staffApplyCar.setStaffId(idApplyCar);
				staffApplyCar.setVehicleType(vehicleType);
				staffApplyCar.setUsercarStaffid(idUseCar);
				staffApplyCar.setApplyResult("waiting");
				applySerI.applyCar(staffApplyCar);
			}

		} catch (Exception e) {
			return "error";
		}
		return "ok";
	}
	
	public String acceptApply(){
		String id = ServletActionContext.getRequest().getParameter("id");
		FcarAplly app = fVApplySerI.getByCidAndRid(Integer.parseInt(id));
		fVApplySerI.acceptCarApply(app);
		return "ok";
	}

	/**
	 * @return the applyDate
	 */
	public Timestamp getApplyDate() {
		return applyDate;
	}

	/**
	 * @return the applyReason
	 */
	public String getApplyReason() {
		return applyReason;
	}

	/**
	 * @return the applySerI
	 */
	public ApplySerI getApplySerI() {
		return applySerI;
	}

	/**
	 * @return the duration
	 */
	public Timestamp getDuration() {
		return duration;
	}

	/**
	 * @return the reviewerId
	 */
	public String getReviewerId() {
		return reviewerId;
	}


	/**
	 * @return the vehicleType
	 */
	public String getVehicleType() {
		return vehicleType;
	}

	/**
	 * @param applyDate
	 *            the applyDate to set
	 */
	public void setApplyDate(Timestamp applyDate) {
		this.applyDate = applyDate;
	}

	/**
	 * @param applyReason
	 *            the applyReason to set
	 */
	public void setApplyReason(String applyReason) {
		this.applyReason = applyReason;
	}

	/**
	 * @param applySerI
	 *            the applySerI to set
	 */
	public void setApplySerI(ApplySerI applySerI) {
		this.applySerI = applySerI;
	}

	/**
	 * @param duration
	 *            the duration to set
	 */
	public void setDuration(Timestamp duration) {
		this.duration = duration;
	}

	/**
	 * @param reviewerId
	 *            the reviewerId to set
	 */
	public void setReviewerId(String reviewerId) {
		this.reviewerId = reviewerId;
	}

	/**
	 * @param vehicleType
	 *            the vehicleType to set
	 */
	public void setVehicleType(String vehicleType) {
		this.vehicleType = vehicleType;
	}

	/**
	 * @return the idApplyCar
	 */
	public String getIdApplyCar() {
		return idApplyCar;
	}

	/**
	 * @param idApplyCar the idApplyCar to set
	 */
	public void setIdApplyCar(String idApplyCar) {
		this.idApplyCar = idApplyCar;
	}

	/**
	 * @return the idUseCar
	 */
	public String getIdUseCar() {
		return idUseCar;
	}

	/**
	 * @param idUseCar the idUseCar to set
	 */
	public void setIdUseCar(String idUseCar) {
		this.idUseCar = idUseCar;
	}

}
